package escom.dds.gestionarmateria.controller;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import escom.dds.gestionarmateria.bussines.MateriaBs;
import escom.dds.modelo.Materia;

public class GestionarMateriaCtrl extends ActionSupport implements
		ModelDriven<Materia> {

	private Materia model;

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private MateriaBs materiaBs;

	private Integer idSel;

	private List<Materia> listMaterias;

	public String index() {
		listMaterias = materiaBs.findAll();
		return "index";
	}

	public String editNew() {
		return "editNew";
	}

	public String create() {
		materiaBs.save(model);
		return index();
	}

	public String edit() {
		return "edit";
	}

	public String update() {
		System.out.println("update---------------------------------");
		materiaBs.update(model);
		return index();
	}

	public String deleteConfirm() {
		return "deleteConfirm";
	}

	public String destroy() {
		return index();
	}

	/**
	 * @return the materiaBs
	 */
	public MateriaBs getMateriaBs() {
		return materiaBs;
	}

	/**
	 * @param materiaBs
	 *            the materiaBs to set
	 */
	public void setMateriaBs(MateriaBs materiaBs) {
		this.materiaBs = materiaBs;
	}

	/**
	 * @return the idSel
	 */
	public Integer getIdSel() {
		return idSel;
	}

	/**
	 * @param idSel
	 *            the idSel to set
	 */
	public void setIdSel(Integer idSel) {
		this.idSel = idSel;
		model = new Materia();
		if (idSel != null) {
			model.setId(idSel);
			model = materiaBs.findById(model);
		}
	}

	/**
	 * @return the listMaterias
	 */
	public List<Materia> getListMaterias() {
		return listMaterias;
	}

	/**
	 * @param listMaterias
	 *            the listMaterias to set
	 */
	public void setListMaterias(List<Materia> listMaterias) {
		this.listMaterias = listMaterias;
	}

	/**
	 * @return the model
	 */
	public Materia getModel() {
		return model;
	}

	/**
	 * @param model
	 *            the model to set
	 */
	public void setModel(Materia model) {
		this.model = model;
	}

}
